<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
<jsp:include page="../common/head.jsp" />
<title>编辑节点</title>
</head>
<body id="node-edit">
	<article class="page-container">
		<form action="node/save.do" method="post" class="form form-horizontal" id="node-form">
			<input type="hidden" value="${node.id}" name="id">
			<input type="hidden" value="${node.flowId}" name="flowId">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>步骤阶段：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="${node.step}" placeholder="" id="step" name="step" number="true" required="true" maxlength="2">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>流程事件：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="${node.name}" placeholder="" id="name" name="name" required="true" maxlength="30">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>人员指定：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<span class="select-box"> <select class="select" size="1" id="operator" name="operator" required="true">
							<option value="">请选择</option>
					</select> </span>
				</div>
			</div>
			
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
				</div>
			</div>
		</form>
	</article>
</body>
<jsp:include page="../common/script.jsp" />
<script type="text/template">
		<tr class="text-c">
			<td>{{step}}</td>
			<td>{{name}}</td>
			<td>{{operatorName}}</td>
			<td class="td-manage">
				<a title="编辑" href="javascript:;" onclick="nodeEdit('updateView?id={{id}}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i> </a> 
				<a title="删除" href="javascript:;" onclick="nodeRemove('{{id}}')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i> </a>
			</td>
		</tr>
</script>
<script type="text/javascript">
	var $dom = $("#node-edit");
	var $form = $dom.find("#node-form");
	var $operator = $dom.find("#operator");
	console.log("${node.flowId}");
	var idDefault = "${node.id}";
	var operatorDefault = "${node.operatorName}";
	$(function() {
		
		/**加载角色*/
		U.initSelect({
			url : "user/list.json",
			$dom : $operator,
			nameField : "name",
			callback : function(_rsp) {
				if (operatorDefault != '') {
					$operator.val(operatorDefault);
				}
			}
		});

		/**校验*/
		$form.validate({
			onkeyup : false,
			focusCleanup : true,
			success : 'valid',
			submitHandler : function(form) {
				var url;
				if (C.isEmpty(idDefault)) {
					url = "node/add.do";
				} else {
					url = "node/update.do";
				}
				ajaxSubmit($form, url, function(_resp) {
					if (_resp.status == '000002') {
						U.alert(_resp.message);
						return;
					}
					U.msg('操作成功', 500, function() {
						var index = window.parent.layer.getFrameIndex(window.name);
						window.parent.load();
						window.parent.layer.close(index);
					});
				});
			}
		});
	});
	
	
	/**编辑*/
	function nodeEdit(url) {
		U.showHtmlDialog('节点编辑', url, '', '200',true)
	}

	/**删除*/
	function nodeRemove(id) {
		U.confirm('确认要删除吗？', function() {
			ajaxCall("node/remove.do", {
				"id" : id
			}, function() {
				U.msg('已删除', 500, function() {
					load();
				});
			});
		});
	}
</script>
</html>